package com.hwua.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 计算时间差的工具
 * @author admin
 */
public class CalculateTimeTools {
    private String rentTime;
    private String returnTime;
    public CalculateTimeTools(String rentTime,String returnTime){
        this.rentTime=rentTime;
        this.returnTime=returnTime;
    }
    public  int calculateTimeDifference() throws ParseException {
        SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd");
        /*天数差*/
        Date startDate = simpleFormat.parse(rentTime);
        Date endDate = simpleFormat.parse(returnTime);
        long start = startDate.getTime();
        long end = endDate.getTime();
        int days = (int) ((end - start) / (1000 * 60 * 60 * 24));
        return days;
    }
}
